class FormController < ApplicationController
	def index
	end
	def save
		f_id=params[:f_id]
	    f_name=params[:f_title]
		f_title=""
		max=params[:max]
		if(f_id==-1)
			@f=Form.new(:form_name => f_name, :form_title => f_title, :no_elements => max)
			puts $f_id
		else
#			del all previous entries
			Form.destroy(f_id)
			@f=Form.new(:id => f_id, :form_name => f_name, :form_title => f_title, :no_elements => max)
		end
		
		for i in (0..(max-1))
			e=params["e#{i}".to_sym];
			//echo "\n".$e;
			qt=params["qt#{i}".to_sym];
			//echo "\n".$qt;
			tt=params["tt#{i}".to_sym];
			re=params["re#{i}".to_sym];
			ty=params["ty#{i}".to_sym];
			@f.form_elements << FormElement.new(:e_type => ty, :e_label => qt, :e_help => tt, :reqd => re)
			if(ty==4||ty==5||ty==6)
				number_of_options = params["op#{i}".to_sym]
				for j in (0..(number_of_options-1))
					label=params["e#{i}#{j}".to_sym]
					if(ty==4)
						@f.form_elements[i] << CheckboxElement.new(:c_label => label, :c_value => value)
					else if(ty==5)
						@f.form_elements[i] << RadioElement.new(:c_label => label, :c_value => value)
					else
						@f.form_elements[i] << SelectElement.new(:c_label => label, :c_value => value)
					end
				end
			end
		end
		@f.save!
	end	
end
